package com.reservation.controller;

import com.reservation.common.Result;
import com.reservation.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 数据统计分析控制器
 */
@RestController
@RequestMapping("/statistics")
@PreAuthorize("hasRole('ADMIN')")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;
    
    /**
     * 获取系统概览统计数据
     * 
     * @return 统计数据
     */
    @GetMapping("/overview")
    public Result<Map<String, Object>> getOverviewStatistics() {
        Map<String, Object> statistics = statisticsService.getOverviewStatistics();
        return Result.success(statistics);
    }
    
    /**
     * 获取预约类型分布数据
     * 
     * @return 预约类型分布数据
     */
    @GetMapping("/reservation/type")
    public Result<List<Map<String, Object>>> getReservationTypeStatistics() {
        List<Map<String, Object>> statistics = statisticsService.getReservationTypeStatistics();
        return Result.success(statistics);
    }
    
    /**
     * 获取预约状态分布数据
     * 
     * @return 预约状态分布数据
     */
    @GetMapping("/reservation/status")
    public Result<List<Map<String, Object>>> getReservationStatusStatistics() {
        List<Map<String, Object>> statistics = statisticsService.getReservationStatusStatistics();
        return Result.success(statistics);
    }
    
    /**
     * 获取近30天预约趋势数据
     * 
     * @return 预约趋势数据
     */
    @GetMapping("/reservation/trend")
    public Result<List<Map<String, Object>>> getReservationTrendStatistics() {
        List<Map<String, Object>> statistics = statisticsService.getReservationTrendStatistics();
        return Result.success(statistics);
    }
    
    /**
     * 获取热门展览排行数据
     * 
     * @param limit 限制数量，默认为5
     * @return 热门展览排行数据
     */
    @GetMapping("/popular/exhibition")
    public Result<List<Map<String, Object>>> getPopularExhibitionStatistics(
            @RequestParam(defaultValue = "5") Integer limit) {
        List<Map<String, Object>> statistics = statisticsService.getPopularExhibitionStatistics(limit);
        return Result.success(statistics);
    }
    
    /**
     * 获取热门解说员排行数据
     * 
     * @param limit 限制数量，默认为5
     * @return 热门解说员排行数据
     */
    @GetMapping("/popular/guide")
    public Result<List<Map<String, Object>>> getPopularGuideStatistics(
            @RequestParam(defaultValue = "5") Integer limit) {
        List<Map<String, Object>> statistics = statisticsService.getPopularGuideStatistics(limit);
        return Result.success(statistics);
    }
}